<?php
 require_once "menu.php";
 $log_type = isset($ticket)?$ticket['Ticket']['logType']:null;
 $category = isset($ticket)?$ticket['Ticket']['category']:null;
 $department = isset($ticket)?$ticket['Ticket']['department']:null;
 $location = isset($ticket)?$ticket['Ticket']['location']:null;
 $item = isset($ticket)?$ticket['Ticket']['item']:null;
 $infrastructure = isset($ticket)?$ticket['Ticket']['infrastructure']:null;
 $charge_to = isset($ticket_extra[0])?$ticket_extra[0]['TicketExtra']['charge_to']:null;
 $actual_cost = isset($ticket_extra[0])?$ticket_extra[0]['TicketExtra']['actual_cost']:null;
 $subject = isset($ticket)?$ticket['Ticket']['subject']:null;
 $details = isset($ticket)?$ticket['Ticket']['details']:null;
 ?>

    <style type="text/css">
        .ticketForm fieldset p.error label { color: red; }
        form.ticketForm label.error {
            display: block;
            margin-left: 1em;
            width: auto;
        }
        div.error {
            background-color: #eee;
            border: 1px dashed red;
            margin: 5px;
            padding: 10px;
        }

        input, select {
            height: 20px;
            font-size: 12px;
        }
    </style>

<table width="100%" class="menubar" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td class="menudottedline" width="40%"><div class="pathway"></div></td>
        <td class="menudottedline" align="right">
            <table cellpadding="0" cellspacing="0" border="0" id="toolbar">
                <tr height="60" valign="middle" align="center">
                    <td>
                        <a class="toolbar" href="javascript: document.getElementById('flag').value='back'; submitthis();">
                        <?php echo $html->image('admin/restore_f2.png', array('align' => 'middle', 'border' => 0)); ?><br>Back
                        </a>
                    </td>
                    <td>
                        <a class="toolbar" href="#">
                        <?php echo $html->image('admin/help_f2.png', array('align' => 'middle', 'border' => 0)); ?><br>Help
                        </a>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<br>
<br>
<div align="center" class="centermain">
    <div class="main">

        <table class="adminheading">
            <tr>
                <th class="info" rowspan="2" nowrap>Ticket Details</th>
            </tr>
        </table>

        <form id="ticketForm" name="ticketForm" action="<?php echo $html->url('/ticket/createticket/'.$ticketId); ?>" method="post">
            <input type="hidden" id="flag" name="data[flag]" />
            <div class="error"></div>
            <table class="adminlist" cellpadding="20">
                <tr>
                    <th colspan="4">&nbsp;</th>
                </tr>
                <tr>
                    <td colspan="4" class="subheader">
                        <label>Ticket Information</label>
                    </td>
                </tr>
                <tr>
                    <td id="input_label"><font color="red"><b>*</b></font>&nbsp;Log Type</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;" colspan="3">
                        <?php echo $form->select('create.log_type', $log_types, $log_type, array('id' => 'log_type', 'style' => 'width: 250px;', 'title' => 'Specify the ticket log type<br/>', 'class' => '{required:true}')); ?>
                    </td>
                </tr>
                <tr>
                    <td id="input_label"><font color="red"><b>*</b></font>&nbsp;Category</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;" colspan="3">
                        <?php echo $form->select('create.category', $categories, $category, array('id' => 'category', 'style' => 'width: 250px;', 'title' => 'Specify ticket category<br/>', 'class' => '{required:true}')); ?>
                    </td>
                </tr>
                <tr>
                    <td id="input_label">&nbsp;Department</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;" colspan="3">
                        <?php echo $form->select('create.department', $departments, $department, array('id' => 'department', 'style' => 'width: 250px;')); ?>
                    </td>
                </tr>
                <tr>
                    <td id="input_label">&nbsp;Location</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;" colspan="3">
                        <?php echo $form->select('create.location', $locations, $location, array('id' => 'location', 'style' => 'width: 250px;')); ?>
                    </td>
                </tr>
                <tr>
                    <td id="input_label">&nbsp;Item</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;" colspan="3">
                        <?php echo $form->select('create.item', $items, $item, array('id' => 'item', 'style' => 'width: 250px;')); ?>
                    </td>
                </tr>
                <tr>
                    <td id="input_label">&nbsp;Infrastructure</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;" colspan="3">
                        <?php echo $form->select('create.infrastructure', $infrastructures, $infrastructure, array('id' => 'infrastructure', 'style' => 'width: 250px;')); ?>
                    </td>
                </tr>
                <tr>
                    <td id="input_label">&nbsp;Charge To</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;" width="300px;">
                        <?php echo $form->select('create.charge_to', $charges, $charge_to, array('id' => 'charge_to', 'style' => 'width: 250px;')); ?>
                    </td>
                    <td id="input_label">&nbsp;Actual Cost</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;">
                        <input type="text" name="data[create][actual_cost]" id="actual_cost" style="width: 150px;" value="<?php echo $actual_cost; ?>" />
                    </td>
                </tr>
                <tr>
                    <td id="input_label"><font color="red"><b>*</b></font>&nbsp;Subject</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;" colspan="3">
                        <input type="text" name="data[create][subject]" id="subject" style="width: 99%" value="<?php echo $subject; ?>" title="Provide a subject of the ticket<br/>" class="{required:true}" />
                    </td>
                </tr>
                <tr>
                    <td id="input_label" valign="top">Summary</td>
                    <td style="border: 1px dotted #ccc; background-color: #efefef;" colspan="3"><textarea id="summary" name="data[create][summary]" style="width: 100%;" title="" class=""><?php echo $details; ?></textarea></td>
                </tr>
                <tr>
                    <td id="input_label">&nbsp;</td>
                    <td colspan="3">
                        <?php
                         if ($ticketId) {
                         ?>
                        <input type="submit" value="Update" name="data[flag]" style="width: 150px; height: 30px;" class="button" />
                        <?php
                         } else {
                         ?>
                        <input type="submit" value="Create" name="data[flag]" style="width: 150px; height: 30px;" class="button" />
                        <?php
                         }
                         ?>

                    </td>
                </tr>
                <!--
                <tr>
                    <td id="input_label">&nbsp;Attached Image:</td>
                    <td id="input_box">
                        <input type="file" name="data[create][attachment]">&nbsp;
                        <label style="font-size: 11px;"><i>Allowed extension .jpg, .png, .gif</i></label>
                    </td>
                </tr>
                -->
            </table>
        </form>


    </div>
</div>

<script type="text/javascript">
    function setdropdowndefault()
    {
        document.getElementById('log_type').selectedIndex = 0;
        document.getElementById('category').selectedIndex = 0;
        document.getElementById('item').selectedIndex = 0;
        document.getElementById('department').selectedIndex = 0;
        document.getElementById('location').selectedIndex = 0;
        document.getElementById('charge_to').selectedIndex = 0;
        document.getElementById('infrastructure').selectedIndex = 0;
    }

    function checkmsg()
    {
        var msg = '<?php echo $msg; ?>';
        if (msg) {
            alert(msg);
        }
    }

    checkmsg();
    setdropdowndefault();

        tinyMCE.init({
        	// General options
        	mode : "textareas",
        	theme : "advanced",
        	plugins : "table,inlinepopups",

        	// Theme options
        	theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,|,table,removeformat,code",
        	theme_advanced_buttons2 : "",
        	theme_advanced_buttons3 : "",
        	theme_advanced_buttons4 : "",
        	theme_advanced_toolbar_location : "top",
        	theme_advanced_toolbar_align : "left",
        	theme_advanced_statusbar_location : "bottom",
        	theme_advanced_resizing : true,

        	// Example content CSS (should be your site CSS)
        	content_css : "/js/tinymce/examples/css/content.css",

        	// Style formats
        	style_formats : [
        		{title : 'Bold text', inline : 'b'},
        		{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
        		{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
        		{title : 'Example 1', inline : 'span', classes : 'example1'},
        		{title : 'Example 2', inline : 'span', classes : 'example2'},
        		{title : 'Table styles'},
        		{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
        	],

        	formats : {
        		alignleft : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'left'},
        		aligncenter : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'center'},
        		alignright : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'right'},
        		alignfull : {selector : 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img', classes : 'full'},
        		bold : {inline : 'span', 'classes' : 'bold'},
        		italic : {inline : 'span', 'classes' : 'italic'},
        		underline : {inline : 'span', 'classes' : 'underline', exact : true},
        		strikethrough : {inline : 'del'},
        		customformat : {inline : 'span', styles : {color : '#00ff00', fontSize : '20px'}, attributes : {title : 'My custom format'}}
        	}
        });

    $().ready(function() {
        $("#ticketForm").validate({
            errorLabelContainer: $("#ticketForm div.error")

        });
    });

    function submitthis()
    {
        var flag = document.getElementById('flag').value;
        switch (flag) {
            case "save":
                document.ticketForm.submit();
                break;

            default:
                document.ticketForm.submit();
                break;
        }
    }
</script>